package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局统一异常处理
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result globalExceptionHandler(Exception ex){
        ex.printStackTrace(); //异常要打印。
        return Result.fail();
    }

    @ExceptionHandler(value = LeaseException.class)
    @ResponseBody
    public Result leaseExceptionHandler(LeaseException ex){
        ex.printStackTrace(); //异常要打印。
        return Result.fail(ex.getCode(),ex.getMessage());
    }
}
